package niuke;

import java.util.Scanner;

public class 牛牛取快递 {
    public static void main(String[] args) {
        int n,m,s,e;
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        m = scanner.nextInt();
        s = scanner.nextInt();
        e = scanner.nextInt();
        int[][] map = new int[n+1][n+1];
        //初始化map
        for(int i=1;i<=n;i++){
            for(int k=1;k<=n;k++){
                if(i != k){
                    map[i][k] = 99999;
                }
            }
        }
        int a[][] = new int[m][3];
        //输入
        for (int i=0;i<m;i++){
            a[i][0] = scanner.nextInt();
            a[i][1] = scanner.nextInt();
            a[i][2] = scanner.nextInt();
        }
        //赋值
        for (int b[]:a){
            map[b[0]][b[1]] = b[2];
        }

        //求起点到终点
        for(int i=1;i<=n;i++){
            if(map[s][e] > map[s][i] + map[i][e]){
                map[s][e] = map[s][i] + map[i][e];
            }
        }
        //求终点到起点
        for(int i=1;i<=n;i++){
            if(map[e][s] > map[e][i] + map[i][s]){
                map[e][s] = map[e][i] + map[i][s];
            }
        }

        System.out.println(map[s][e] + map[e][s]);
    }

}
